package com.yunsc.shop.controller.shop;


import com.yunsc.common.utils.RedisUtils;
import com.yunsc.common.utils.Result;
import com.yunsc.shop.utils.ClientInfoUtils;
import com.yunsc.store.service.YunscLoginService;
import com.yunsc.system.dto.SmsCaptchaDTO;
import com.yunsc.system.vo.PicVerifyCodeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Random;

/**
 * @author Mr.M
 * @version 1.0
 * @description 验证码服务接口
 * @date 2022/9/29 18:39
 */
@Api(value = "验证码服务接口")
@RestController
@RequestMapping("captcha")
public class CheckCodeController {

    @Resource
    private YunscLoginService loginService;
    @Resource
    private RedisUtils redisUtils;
    @Resource
    private ClientInfoUtils clientInfoUtils;


    @ApiOperation(value="生成验证信息", notes="生成验证信息")
    @GetMapping(value = "/image")
    public Result<?> generatePicCheckCode(){
        PicVerifyCodeVO picVerifyCodeVO = loginService.generatePicCheckCode();
        return Result.ok(picVerifyCodeVO);
    }

    // sendSmsCaptcha
    // 获取手机验证码
    @ApiOperation(value="获取手机验证码", notes="获取手机验证码")
    @PostMapping(value = "/sendSmsCaptcha")
    public Result<?> sendSmsCaptcha(@RequestBody SmsCaptchaDTO smsCaptchaDTO){
        loginService.sendSmsCaptcha(smsCaptchaDTO, clientInfoUtils.getCurrentStoreId());
        // String code = (String) redisUtils.get(smsCaptchaDTO.getForm().getMobile());
        return Result.ok("验证码发送成功，请注意查收");
    }



    @ApiOperation(value = "发送手机/邮箱验证码", tags = "发送手机/邮箱验证码")
    @PostMapping("/phone")
    public void sendEMail(@RequestParam("param1") String param) {
        // String code = MailUtil.achieveCode();
        Random randObj = new Random();
        // 生成6位随机验证码
        // String code = Integer.toString(100000 + randObj.nextInt(900000));
        // 生成4位随机验证码
        String code = Integer.toString(1000 + randObj.nextInt(9000));
        // sendCodeService.sendEMail(param, code);
    }
}
